<?php
include("../dynamicContent.php");
conexionBaseDatos();

if (isset($_GET["tipo"]) && isset($_GET["red"])){
$tipo = $_GET["tipo"];
$red = $_GET["red"];
$IDGlobal = $_GET["ID"];

if ($tipo == 1){//Data
echo "-".$_FILES["file"]["type"]."-";
echo "   ()   ";
echo "-".$_FILES["file"]["name"]."-";
if ($_FILES["file"]["name"] == ""){ //sin imagen

	  $sql = "update cat_Dato set FKID_Categoria = '{$_POST['categoria']}', FKID_Idioma = '{$_POST['idioma']}', FKID_Ubicacion = '{$_POST['ubicacion']}', nombreDato = '{$_POST['titulo']}',descripcionDato = '{$_POST['descripcion']}',fechaUltimaModificacion= NOW() where ID_Dato = $IDGlobal";
	  $resultado = mysql_query($sql);	  
	  
	  //Modificar fecha de Ubicacion
	    $sql = "update cat_Ubicacion set fechaUltimaActualizacion = NOW() where ID_Ubicacion = '{$_POST['ubicacion']}'";
	  $resultado = mysql_query($sql);	  
	echo "<script type='text/javascript' >alert('Data modified succesfully');</script>";	  
	  echo "<script type='text/javascript' >window.location='$red';</script>";




}
//con imagen
else if ((  ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp"))
&& ($_FILES["file"]["size"] < 20000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
		  echo "<script type='text/javascript' >alert('Error');</script>";
	  echo "<script type='text/javascript' >window.location='$red';</script>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("../images/data/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
	  echo "<script type='text/javascript' >alert('Image alredy exists.');</script>";
	  echo "<script type='text/javascript' >window.location='$red';</script>";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "../images/data/" . $_FILES["file"]["name"]);
	  $link = $_FILES["file"]["name"];	
	  	
	  //Borrar imagen anterior de Dato
	$sql = "SELECT imagenDato FROM cat_Dato where ID_Dato = '$IDGlobal'";
			$resultado = mysql_query($sql);
			if($row = mysql_fetch_assoc($resultado)){
				$imagenR = $row["imagenDato"];
				unlink("../images/data/$imagenR");
			}
	  
	  
	  
	  
	  //Modificar 
	$sql = "update cat_Dato set FKID_Categoria = '{$_POST['categoria']}', FKID_Idioma = '{$_POST['idioma']}', FKID_Ubicacion = '{$_POST['ubicacion']}', nombreDato = '{$_POST['titulo']}',descripcionDato = '{$_POST['descripcion']}',fechaUltimaModificacion= NOW(), imagenDato = '$link' where ID_Dato = '$IDGlobal'";
	  $resultado = mysql_query($sql);	  
	  
	  //Modificar fecha de Ubicacion
	    $sql = "update cat_Ubicacion set fechaUltimaActualizacion = NOW() where ID_Ubicacion = '{$_POST['ubicacion']}'";
	  $resultado = mysql_query($sql);	  
	echo "<script type='text/javascript' >alert('Data modified succesfully');</script>";	  
	  echo "<script type='text/javascript' >window.location='$red';</script>";
	  	  
     }
    }
  }
else
  {
  echo "Invalid file";
echo "<script type='text/javascript' >alert('Invalid Image');</script>";
echo "<script type='text/javascript' >window.location='$red';</script>";

}
}

else if ($tipo == 2){//Phrases
$sql = "update frase set FKID_CategoriaFrase = '{$_POST['categoria']}', tituloFrase = '{$_POST['titulo']}',contenidoFrase = '{$_POST['descripcion']}',fechaUltimaActualizacion= NOW() where ID_frase = '$IDGlobal'";
	  $resultado = mysql_query($sql);
	echo "<script type='text/javascript' >alert('Phrase modified succesfully');</script>";	  
	  echo "<script type='text/javascript' >window.location='$red';</script>";

}

else if ($tipo == 3){//Abstracts
echo "-".$_FILES["file"]["type"]."-";
echo "   ()   ";
echo "-".$_FILES["file"]["name"]."-";
if ($_FILES["file"]["name"] == ""){ //sin imagen

	  $sql = "update abstracto set nombreAbstracto = '{$_POST['titulo']}',UltimaActualizacion= NOW() where ID_abstracto = $IDGlobal";
	  $resultado = mysql_query($sql);	  
	  
	echo "<script type='text/javascript' >alert('Data modified succesfully');</script>";	  
	  echo "<script type='text/javascript' >window.location='$red';</script>";




}
//con imagen
else if ((  ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp"))
&& ($_FILES["file"]["size"] < 20000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
		  echo "<script type='text/javascript' >alert('Error');</script>";
	  echo "<script type='text/javascript' >window.location='$red';</script>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("../images/abstracts/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
	  echo "<script type='text/javascript' >alert('Image alredy exists.');</script>";
	  echo "<script type='text/javascript' >window.location='$red';</script>";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "../images/abstracts/" . $_FILES["file"]["name"]);
	  $link = $_FILES["file"]["name"];		
	  
	  	  //Borrar imagen anterior de Abstracto
	$sql = "SELECT imagenAbstracto FROM abstracto where ID_Abstracto = '$IDGlobal'";
			$resultado = mysql_query($sql);
			if($row = mysql_fetch_assoc($resultado)){
				$imagenR = $row["imagenAbstracto"];
				unlink("../images/abstracts/$imagenR");
			}
	  
	  
	  
	  
	$sql = "update abstracto set nombreAbstracto = '{$_POST['titulo']}',UltimaActualizacion= NOW(), imagenAbstracto = '$link' where ID_abstracto = $IDGlobal";
	  $resultado = mysql_query($sql);	  
	  	  
	echo "<script type='text/javascript' >alert('Abstract modified succesfully');</script>";	  
	  echo "<script type='text/javascript' >window.location='$red';</script>";
	  	  
     }
    }
  }
else
  {
  echo "Invalid file";
echo "<script type='text/javascript' >alert('Invalid Image');</script>";
echo "<script type='text/javascript' >window.location='$red';</script>";

}
}



else if ($tipo == 999){//Banner Image
echo "-".$_FILES["file"]["type"]."-";
echo "   ()   ";
echo "-".$_FILES["file"]["name"]."-";
if ((  ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")|| ($_FILES["file"]["type"] == "image/png")  || ($_FILES["file"]["type"] == "image/bmp"))
&& ($_FILES["file"]["size"] < 20000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
		  echo "<script type='text/javascript' >alert('Error');</script>";
	  echo "<script type='text/javascript' >window.location='$red';</script>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("../images/banner/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
	  echo "<script type='text/javascript' >alert('Image alredy exists.');</script>";
	  echo "<script type='text/javascript' >window.location='$red';</script>";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "../images/banner/" . $_FILES["file"]["name"]);
	  $link = $_FILES["file"]["name"];		
	  
	  	  //Borrar imagen anterior de Abstracto
		  /*
	$sql = "SELECT * FROM informacionGeneral  where ID_infoGeneral = '1'";
			$resultado = mysql_query($sql);
			if($row = mysql_fetch_assoc($resultado)){
				$imagenR = $row["imagenSitio"];
				unlink("../images/banner/$imagenR");
			}
	  */
	  
	  
	  
	$sql = "update informacionGeneral set fechaUltimaActualizacion = NOW(), imagenSitio = '$link' where ID_infoGeneral = '1'";
	  $resultado = mysql_query($sql);	  
	  	  
	echo "<script type='text/javascript' >alert('Banner Image modified succesfully');</script>";	  
	  echo "<script type='text/javascript' >window.location='$red';</script>";
	  	  
     }
    }
  }
else
  {
  echo "Invalid file";
echo "<script type='text/javascript' >alert('Invalid Image');</script>";
echo "<script type='text/javascript' >window.location='$red';</script>";

}
}




else if ($tipo == 998){//Title and Subtitle
	$sql = "update informacionGeneral set fechaUltimaActualizacion = NOW(), tituloInicio = '{$_POST['titulo']}', descripcionInicio = '{$_POST['descripcion']}'  where ID_infoGeneral = '1'";
	  $resultado = mysql_query($sql);	  
	  	  
	echo "<script type='text/javascript' >alert('Information modified succesfully');</script>";	  
	  echo "<script type='text/javascript' >window.location='$red';</script>";
}















}





?>